package com.hbyj.struts.action;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.apache.poi.hssf.record.formula.functions.Db;
import org.apache.struts2.ServletActionContext;

import com.hbyj.db.function.DbTools;
import com.hbyj.hbm.vo.Jbqk01;
import com.hbyj.hbm.vo.Jbqk01temp;
import com.hbyj.hbm.vo.YjdcYjdc06;
import com.hbyj.util.Constants;
import com.hbyj.util.PageClass;
import com.opensymphony.xwork2.ActionSupport;

public class DcwdAction extends ActionSupport{
	private String jsonResult;
	private int total;
	private List rows = new ArrayList();
	
	public String getJsonResult() {
		return jsonResult;
	}

	public void setJsonResult(String jsonResult) {
		this.jsonResult = jsonResult;
	}

	public int getTotal() {
		return total;
	}

	public void setTotal(int total) {
		this.total = total;
	}

	public List getRows() {
		return rows;
	}

	public void setRows(List rows) {
		this.rows = rows;
	}
	
	public String queryDCWD(){
		HttpServletRequest request = ServletActionContext.getRequest();
		String pageNo = request.getParameter("page");
		int pageSize = Constants.PAGE_KEY;
		String zhCode = request.getParameter("zhCode");
		String startTime = request.getParameter("startTime");
		String endTime = request.getParameter("endTime");
		String conStr = "";
		String conStrForSql = "";
		if(!"".equals(startTime)){
			conStr += " and yjdc06080 >='"+startTime+"' ";
			conStrForSql = "and YJDC06080 >='"+startTime+"'";
		}
		if(!"".equals(endTime)){
			conStr += " and yjdc06080 <='"+endTime+"'";
			conStrForSql += "and YJDC06080 <='"+endTime+"'";
		}
		///修改by  cuiyi   在汉口。 业务需求问题变更，不恩能够用jbqk0102 = '3'
		String hql = "from YjdcYjdc06 where    yjdc06000 like '"+zhCode+"'"+conStr+" order by yjdc06080";
		String countHql = "select count(*) from YJDC_YJDC06 where YJDC06000 like '"+zhCode+"'"+conStrForSql;

		int t = DbTools.getDataSQLCount(countHql);
		PageClass page = new PageClass();
		page.setPageShow(pageSize);  //设置每页显示的行数
		page.setPageCount(t);  //设置总页数
		page.setCurrentPage(Integer.parseInt(pageNo));  //设置当前页
		int first=page.getNextIndex(); //获得开始的索引值
		int max=page.getPageShow();  //获得每次显示的值
		List list = (List)DbTools.findPageHQL(first, max,hql);
		rows = findNameByCode(list);
		
		total = t;
		return SUCCESS;
	}
	private List findNameByCode(List list){
		List res = new ArrayList();
		String sql = "";
		for(int i=0;i<list.size();i++){
			YjdcYjdc06 yjdc06 = (YjdcYjdc06)list.get(i);
			if(yjdc06 ==null) 
				continue;
			Jbqk01 jbqk = new Jbqk01();
			jbqk.setJbqk0110("暂无");
			Object[] obj = new Object[2];
			obj[0]=yjdc06;
			sql = "from Jbqk01 where id.jbqk0100='"+yjdc06.getYjdc06000()+"'";
			List listTmp = DbTools.findByHql(sql);
			obj[1]= listTmp.size()>0?listTmp.get(0):jbqk;
			res.add(obj);
		}
		return res;
	}
}
